import { createStoreBindings } from '@/miniprogram_npm/mobx-miniprogram-bindings/index';
import tabbarStore from '@/store/tabbar';

Component({
    lifetimes: {
        attached() {
            this.storeBindings = createStoreBindings(this, {
                store: tabbarStore,
                fields: ['current'],
                actions: ['setCurrent']
            });
        }
    },

    data: {
        list: [
            {
                value: 'home',
                icon: 'home',
                ariaLabel: '首页',
                path: '/pages/index/index'
            },
            {
                value: 'predict',
                icon: 'control-platform',
                ariaLabel: '预测',
                path: '/pages/predict/pages/index/index'
            },
            {
                value: 'user',
                icon: 'user-setting',
                ariaLabel: '我的',
                path: '/pages/user/user'
            }
        ]
    },
    methods: {
        onChange(e) {
            this.setCurrent(e.detail.value);
            wx.switchTab({
                url: this.data.list.find((item) => item.value === e.detail.value).path
            });
        }
    }
});
